﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using Project.Engine.Control;
using Project.Engine.Utilities;
using Project.Module.Model;
using Project.Module.DAO;
using Project.Module.DAO.BL;

namespace Project.Module.View
{
    public class Catagory : DocumentInfo
    {
        public List<ProductModel> listProduct = null;
        private EventBL eventBl = new EventBL();
        private ProductBL productBl = new ProductBL();

        public int totalRecord = 0;
        public int pageSize = DefineUtil.pageSize;
        public int pageIndex = 1;
        public int cateId = 0;

        public string displayuser = String.Empty;
        public string cateName = String.Empty;

        public Catagory(int nodeid, string nodealias, string _username)
        {
            Init(nodeid, nodealias, _username);
        }

        private void Init(int nodeid, string nodealias, string _username)
        {
            this.displayuser = _username;
            this.cateName = ConvertUtil.GetCategoryName(nodealias);
            this.cateId = ConvertUtil.GetCateIdByCateName(this.cateName);
            this.pageIndex = ProcessUrl.GetPageIdByUrl(nodealias);
            GetListCategory();
        }

        private void GetListCategory()
        {
            this.listProduct = productBl.GetListProduct(this.cateId, (pageIndex * pageSize), pageSize, ref totalRecord);
            if (this.listProduct != null)
            {
                foreach (var item in this.listProduct)
                {
                    item.url = StringUtil.UnicodeToKoDauUrl(StringUtil.ShortContent(item.Description, 5));
                    item.ImagePath = eventBl.GetImagePathById(item.ImageID);
                    item.title = StringUtil.ShortContent(item.Description, 5);
                    item.summary = StringUtil.ShortContent(item.Description, 20);
                }
            }
        }
    }
}
